import request from "@/utils/request.ts";
import {ICommonResponse, ISqlUpdate} from "@/global.ts";
import React from "react";

export const addFolder = (data: { fileName: string, state: string, type: string, parentFileUID: string }): Promise<ICommonResponse<{ msg: string }>> => {
    return request({
        url: '/file/add/folder',
        method: 'POST',
        data
    })
}
export interface IFile {
    key: React.Key
    userFileUID: string
    userUID: string
    state: string
    fileName: string
    fileUID: string
    parentFileUID: string
    path: string
    size: number
    time: string
    type: string
}
export const fileList = (data: { fileUID: string }): Promise<ICommonResponse<Array<IFile>>> => {
    return request({
        url: '/file/list',
        method: 'POST',
        data
    })
}

// 删除
export const fileDel = (data: Array<string>): Promise<ICommonResponse<ISqlUpdate>> => {
    return request({
        url: '/file/del',
        method: 'POST',
        data: { fileUIDList: data }
    })
}

// 下载
export const fileDownload = (url: string): Promise<Blob> => {
    return request({
        url,
        method: 'GET',
        responseType: 'blob'
    })
}